/**
 * session或者localstrorage相关缓存配置
 */
export const SessionCommon = {
	/**
	 * 获取当前登录人
	 * @returns
	 */
	getCurUserName() {
		return SessionCommon.getUserInfo().realname
			? SessionCommon.getUserInfo().realname
			: SessionCommon.getUserInfo().username
	},
	/**
	 * 获取用户id
	 * @returns
	 */
	getCurUserId() {
		return SessionCommon.getUserInfo().id
	},
	/**
	 * 设置当前点击的菜单信息
	 * @param {*} menuInfo
	 */
	setCurrentMenuInfo(menuInfo) {
		console.log(menuInfo, "menuInfo.....1")
		window.sessionStorage.setItem("menuInfo", JSON.stringify(menuInfo))
	},
	/**
	 * 获取当前点击后的菜单信息
	 * @returns  字符串 {id:"xxx",title:"xxx",menuUrl:"xxxx"}
	 */
	getCurrentMenuInfo() {
		var menuInfo = window.sessionStorage.getItem("menuInfo")
		console.log(menuInfo, "menuInfo.....2")
		return menuInfo
	},
	/**
	 * 清空当前点击的菜单信息
	 * @returns
	 */
	clearCurrentMenuInfo() {
		return window.sessionStorage.setItem("menuInfo", "")
	},
	/**
	 * 设置菜单list集合
	 * @param {*} menuList
	 */
	setAllMenuList(menuList) {
		window.sessionStorage.setItem("menuList", JSON.stringify(menuList))
	},
	/**
	 * 获取菜单集合
	 * @returns
	 */
	getAllMenuList() {
		return window.sessionStorage.getItem("menuList")
	},
	/**
	 * 获取字典类型值
	 * @param {*} type
	 */
	getDictValue(type) {
		const dictData = window.sessionStorage.getItem("dict")
		return dictData[type]
	},

	getCurDateTime(fmt) {
		var myDate = new Date()
		var o = {
			"M+": myDate.getMonth() + 1, //月份
			"d+": myDate.getDate(), //日
			"H+": myDate.getHours(), //小时
			"m+": myDate.getMinutes(), //分
			"s+": myDate.getSeconds(), //秒
			"q+": Math.floor((myDate.getMonth() + 3) / 3), //季度
			S: myDate.getMilliseconds(), //毫秒
		}
		if (/(y+)/.test(fmt))
			fmt = fmt.replace(
				RegExp.$1,
				(myDate.getFullYear() + "").substr(4 - RegExp.$1.length)
			)
		for (var k in o)
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(
					RegExp.$1,
					RegExp.$1.length == 1
						? o[k]
						: ("00" + o[k]).substr(("" + o[k]).length)
				)

		return fmt
	},
	/**
	 *  获取登录的用户信息
	 */
	getUserInfo() {
		let userInfo = localStorage.getItem("userInfo")
		// {
		//   "id": "e9ca23d68d884d4ebb19d07889727dae",
		//   "username": "admin",
		//   "realname": "管理员",
		//   "avatar": "https://static.jeecg.com/temp/国炬软件logo_1606575029126.png",
		//   "birthday": "2018-12-05",
		//   "sex": 1,
		//   "email": "jeecg@163.com",
		//   "phone": "18611111111",
		//   "orgCode": "A01",
		//   "orgCodeTxt": null,
		//   "status": 1,
		//   "delFlag": 0,
		//   "workNo": "00001",
		//   "post": "总经理",
		//   "telephone": null,
		//   "createBy": null,
		//   "createTime": "2019-06-21 17:54:10",
		//   "updateBy": "admin",
		//   "updateTime": "2022-03-09 22:50:20",
		//   "activitiSync": 1,
		//   "userIdentity": 2,
		//   "departIds": "c6d7cb4deeac411cb3384b1b31278596",
		//   "relTenantIds": "",
		//   "clientId": null,
		//   "homePath": null
		// }
		return JSON.parse(userInfo)
	},
}
